""""
个人资料页面
"""
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select
from page.login_page import LoginPage


class Personal_Page(BasePage):
    url="/crm/index.php?m=user&a=edit"
    #属性（定位器）
    headportrait_locator = (By.ID, "file_upload")
    name_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input[type=text]")
    user_classes_locator = (By.ID, "category_id")
    account_status_locator = (By.ID, "status")
    defpartment_locator = (By.ID, "department")
    role_locator = (By.ID, "role")
    man_locator = (By.XPATH, "/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[10]/td[2]/input[1]")
    woman_locator = (By.XPATH, "/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[10]/td[2]/input[2]")
    email_locator = (By.CSS_SELECTOR,
                     "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input")
    phone_locator = (By.CSS_SELECTOR,
                     "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(12) > td:nth-child(2) > input")
    contactaddress_locator = (By.CSS_SELECTOR,
                              "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(13) > td:nth-child(2) > textarea")
    save_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div:nth-child(2) > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")
    # 提示添加成功定位器
    div_class_locator = (By.XPATH, "/html/body/div[5]/div[2]/div[1]/div")


    #方法（操作动作）
    #上传头像
    def pull_touxiang(self,xpath):
        self.driver.find_element(*self.headportrait_locator).send_keys(xpath)
    # 清理用户名输入框
    def clear_name(self):
        self.driver.find_element(*self.name_locator).clear()
    # 输入长用户名
    def insert_name(self,alert_name):
          self.driver.find_element(*self.name_locator).send_keys(alert_name)
    # 用户类别选择框在选用户类别
    def select_user_classes(self,user_classes_value):
        a = self.driver.find_element(*self.user_classes_locator)
        Select(a).select_by_value(user_classes_value)
    # 账号状态选择框选择状态
    def select_account_status(self,account_status_value):
        b = self.driver.find_element(*self.account_status_locator)
        Select(b).select_by_value(account_status_value)
    # 部门选择框选择部门
    def select_department(self,defpartment_value):
        c = self.driver.find_element(*self.defpartment_locator)
        Select(c).select_by_value(defpartment_value)
    # 岗位选择框选择岗位
    def select_role(self,role_value):
        c = self.driver.find_element(*self.role_locator)
        Select(c).select_by_value(role_value)
    #性别选择男
    def selec_sex_man(self):
        self.driver.find_element(*self.man_locator).click()

    # 性别选择男
    def selec_sex_woman(self):
        self.driver.find_element(*self.woman_locator).click()
    # 清理邮箱输入框
    def clear_email(self):
        self.driver.find_element(*self.email_locator).clear()
    # 输入新邮箱
    def input_email(self,email):
        self.driver.find_element(*self.email_locator).send_keys(email)
    # 清理手机输入框
    def clear_phonenumber(self):
        self.driver.find_element(*self.phone_locator).clear()
    # 输入新手机号码
    def input_phonenumber(self,phonenumber):
        self.driver.find_element(*self.phone_locator).send_keys(phonenumber)
    # 清理联系地址
    def clear_address(self):
        self.driver.find_element(*self.contactaddress_locator).clear()
    # 输入新联系地址
    def input_contactaddress(self,address):
        self.driver.find_element(*self.contactaddress_locator).send_keys(address)
    # 点击保存
    def click_save_btn(self):
        self.driver.find_element(*self.save_locator).click()

    #验证修改内容是否符合
    def verify_username(self,username,password):
        a=LoginPage(self.driver)
        a.login(username,password)


    def verify_contactaddress(self):
        contactaddress_text=self.driver.find_element(*self.contactaddress_locator).text
        return contactaddress_text


    def save_successfully(self):
        div_class_value = self.driver.find_element(*self.div_class_locator).get_attribute("class")
        return div_class_value
